import os

str = '/usr/local/app/aaa.war'

print os.path.basename(os.path.dirname(str))

print os.path.basename(os.path.dirname(os.path.dirname(str)))